#include <future>
#include <iostream>
#include <string>

std::string DoTimeCostWork(int nId)
{
    for (int i = 1; i<nId; i++)
    {
	std::cout << "count..." << std::endl;
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }
    return "包子三斤四两";
}

int main()
{
    std::future<std::string> fut = std::async(DoTimeCostWork, 3);

    // 每100毫秒轮询查看任务执行进度
    std::chrono::milliseconds tSpan(100);
    while (fut.wait_for(tSpan) != std::future_status::ready)
    {
        std::cout << "客观别急，任务还没完" << std::endl;
    }

    // 获取执行结果
    std::cout << "\n异步任务执行完毕：" << fut.get() << std::endl;

    return 0;
}
